﻿<%@ WebHandler Language="C#" Class="LOVHandler" %>

using System;
using System.Web;
using System.Web.UI;

using LMD.Constant;
using LMD.Lib.Interface;

public class LOVHandler : IHttpHandler {
    
    String sxOutput = String.Empty;
    
    public void ProcessRequest (HttpContext ctx) {
        String sxLOVname = ctx.ReadQuery("lovname");

        if (String.IsNullOrEmpty(sxLOVname))
        {
            ctx.Response.Write("No LOV name specified!!!");
            return;
        }
        
        String sxAction = ctx.ReadQuery("action");

        if (String.IsNullOrEmpty(sxAction))
        {
            ctx.Response.Write("No Action specified!!!");
            return;
        }
        
        String sxControlId = ctx.ReadQuery("cid");

        if (String.IsNullOrEmpty(sxControlId))
        {
            ctx.Response.Write("No Control ID specified!!!");
            return;
        }
        
        String sxFilter = ctx.ReadQuery("filter");
        String sxValue = ctx.ReadQuery("value");
        String sxCustomParam = ctx.ReadQuery("customparam");
        String sxOldDataTypeId = ctx.ReadQuery("olddt");
        int iNewDataTypeId = ctx.ReadInt("datatype");
        int iIndex = ctx.ReadInt("index");
        int iPageSize = ctx.ReadInt("size", KGlobal.DEFAULT_LOV_PAGESIZE);

        ILOVProvider lovProvider = LOVProvider.getProvider(sxLOVname);

        switch (sxAction.ToUpper())
        {
            case KLOV.Action.ADDNEW:
                sxOutput = lovProvider.ShowInputForm(sxControlId, sxValue.ReplaceQuotesForJS(), sxCustomParam);
                break;
            case KLOV.Action.DRAW:
                sxOutput = lovProvider.DrawLOV(sxControlId, sxFilter.ReplaceQuotesForJS(), sxCustomParam, iIndex, iPageSize);
                break;
            case KLOV.Action.GETEDITOR:
                sxOutput = lovProvider.GetEditor(sxControlId, sxValue.ReplaceQuotesForJS(), sxOldDataTypeId, sxCustomParam);
                break;
            case KLOV.Action.INSERT:
                TextboxType tpTextbox = (TextboxType)iNewDataTypeId;
                sxOutput = lovProvider.Insert2LOV(sxValue.ReplaceQuotesForJS(), sxCustomParam, tpTextbox);
                break;
        }
        
        ctx.Response.ContentType = "text/plain";        
        ctx.Response.Write(sxOutput);
    }

    
 
    public bool IsReusable {
        get {
            return false;
        }
    }
    

}